﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace ARS.Control.Custom.Entity.Widget
{
    public class EntityModifyList:EntityModifyPanel
    {
        public EntityModifyList()
        {
            //this.Number = 1;
        }

        public int Number
        {
            get;
            set;
        }
        /// <summary>
        /// 控件列表到实体
        /// </summary>
        public void ControlListToEntity()
        {
            string n = HttpContext.Current.Request.Form["entity_number"]??Number.ToString();
            int number = Int32.Parse(n);
            for (int i = 0; i < number; i++)
            {
                foreach (var control in EntityTableInfo.FieldList)
                {
                    control.Html_Control_Name = control.Html_Control_Name + i.ToString();
                }
                base.ControlToEntity();
                //object obj = base.Entity;
                //int a = 1;
                base.AddOrUpdateEntityToDb();
            }
            
        }

        public override int AddOrUpdateEntityToDb()
        {
            this.ControlListToEntity();
            return 1;
        }

        //override addor

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {

            //string Html_Control_Name=null;// = control.Field.Html_Control_Name;
            //writer.Write("<table>");
            for (int i = 0; i < Number; i++)
            {
                foreach (var control in EntityTableInfo.FieldList)
                {
                    control.Html_Control_Name = control.Html_Control_Name + i.ToString();
                }

                //writer.Write(string.Format("第{0}项</br>", i + 1));

                writer.Write(string.Format("<table id=\"table_entity_{0}\">",i+1));
                base.RenderContents(writer);
                writer.Write("</table>");
                //writer.Write("<div>");
                
                //writer.Write("</div>");
                //writer.Write("<tr><td>----</td><td>----</td></tr>");
            }
            
        }
    }
}
